using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Windows.Forms;


namespace Krilib.Control
{
    /// <summary>
    /// Message Object
    /// </summary>
    abstract public class MessageObject : Base.TimelineMouseControllableItem
    {

        /// <summary>
        /// Returns this object's info by string
        /// </summary>
        public override string ToString() { return null; }

        /// <summary>
        /// Execute draw operation
        /// </summary>
        /// <param name="g">Graphics instance</param>
        /// <param name="location">Rendering start location</param>
        abstract public void Draw(Graphics g, Point location);

        /// <summary>
        /// Premeasuring operation
        /// </summary>
        /// <param name="target">draw target rect</param>
        /// <param name="initHeight">initial height</param>
        /// <returns></returns>
        abstract public IEnumerable<Rectangle> Measure(Rectangle target, int initHeight);

        /// <summary>
        /// Rectangle which suggests measure-ending rect
        /// </summary>
        abstract public Rectangle MeasureEndRect { get; }

        /// <summary>
        /// Release using all resources
        /// </summary>
        abstract public void Reset();

        /// <summary>
        /// Measuring helpers
        /// </summary>
        static protected class Measuring
        {
            /// <summary>
            /// Horizontal Shift Rectangle
            /// </summary>
            /// <param name="rect">rectangle</param>
            /// <param name="horz">shift</param>
            /// <returns>shiftable</returns>
            static public void HorizontalShift(ref Rectangle rect, int horz)
            {
                if (rect.Width < horz)
                {
                    NewLine(ref rect);
                    return;
                }
                rect.Width -= horz;
                rect.X += horz;
            }

            /// <summary>
            /// Create Newline
            /// </summary>
            /// <param name="rect">rect</param>
            static public void NewLine(ref Rectangle rect)
            {
                rect.Width = rect.Right;
                rect.X = 0;
                rect.Y = rect.Bottom;
                rect.Height = 0;
            }
        }
    }
}
